package data;

import java.util.HashMap;

import data.Binary.BinaryType;

public class MutualExclusive implements Constraint{
	public Item VariableA;
	public Item VariableB;
	public Bag ValueA;
	public Bag ValueB;
	
	public MutualExclusive(Item variableA, Item variableB, Bag valueA, Bag valueB) {
		VariableA = variableA;
		VariableB = variableB;
		ValueA = valueA;
		ValueB = valueB;
	}
	
	public boolean IsSatisfied() {
		if (VariableA.Domain.contains(ValueA) && VariableB.Domain.contains(ValueB)) {
			return false;
		}
		
		if (VariableA.Domain.contains(ValueB) && VariableB.Domain.contains(ValueA)) {
			return false;
		}
		
		return true;
	}

	@Override
	public boolean IsSatisfied(HashMap<Item, Bag> assignments) {
		boolean containsA, containsB;
		
		containsA = assignments.containsKey(VariableA);
		containsB = assignments.containsKey(VariableB);
		
		if (containsA && containsB) {
			if (assignments.get(VariableA).Name.equals(ValueA.Name) && 
				assignments.get(VariableB).Name.equals(ValueB.Name)) {
				return false;
			}
			
			if (assignments.get(VariableA).Name.equals(ValueB.Name) && 
					assignments.get(VariableB).Name.equals(ValueA.Name)) {
				return false;
			}
			
			return true;
		} else if (!containsA && containsB) {
			if (VariableA.Domain.contains(ValueA) && 
				assignments.get(VariableB).Name.equals(ValueB.Name)) {
				return false;
			}
				
			if (VariableA.Domain.contains(ValueB) && 
				assignments.get(VariableB).Name.equals(ValueA.Name)) {
				return false;
			}
				
			return true;
		} else if (containsA && !containsB) {
			if (VariableB.Domain.contains(ValueB) && 
				assignments.get(VariableA).Name.equals(ValueA.Name)) {
				return false;
			}
				
			if (VariableB.Domain.contains(ValueA) && 
				assignments.get(VariableA).Name.equals(ValueB.Name)) {
				return false;
			}
				
			return true;
		} else if (!containsA && !containsB) {
			return IsSatisfied();
		}
		
		return IsSatisfied();
	}
}
